package com.homeparking.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.homeparking.common.annotation.Log;
import com.homeparking.common.core.controller.BaseController;
import com.homeparking.common.core.domain.AjaxResult;
import com.homeparking.common.enums.BusinessType;
import com.homeparking.manage.domain.ManageArea;
import com.homeparking.manage.service.IManageAreaService;
import com.homeparking.common.utils.poi.ExcelUtil;

/**
 * 省市县Controller
 * 
 * @author liuyangyang
 * @date 2025-10-24
 */
@RestController
@RequestMapping("/manage/manage_area")
public class ManageAreaController extends BaseController
{
    @Autowired
    private IManageAreaService manageAreaService;

    /**
     * 查询省市县列表
     */
    @GetMapping("/list")
    public AjaxResult list(ManageArea manageArea)
    {
        List<ManageArea> list = manageAreaService.selectManageAreaList(manageArea);
        return success(list);
    }

    /**
     * 导出省市县列表
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_area:export')")
    @Log(title = "省市县", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ManageArea manageArea)
    {
        List<ManageArea> list = manageAreaService.selectManageAreaList(manageArea);
        ExcelUtil<ManageArea> util = new ExcelUtil<ManageArea>(ManageArea.class);
        util.exportExcel(response, list, "省市县数据");
    }

    /**
     * 获取省市县详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_area:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
    {
        return success(manageAreaService.selectManageAreaByAreaId(areaId));
    }

    /**
     * 新增省市县
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_area:add')")
    @Log(title = "省市县", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ManageArea manageArea)
    {
        return toAjax(manageAreaService.insertManageArea(manageArea));
    }

    /**
     * 修改省市县
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_area:edit')")
    @Log(title = "省市县", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ManageArea manageArea)
    {
        return toAjax(manageAreaService.updateManageArea(manageArea));
    }

    /**
     * 删除省市县
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_area:remove')")
    @Log(title = "省市县", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Long[] areaIds)
    {
        return toAjax(manageAreaService.deleteManageAreaByAreaIds(areaIds));
    }
}
